
<!--复制主表订单-->
<!--复制弹出框-->
<div class="wizard" id="wizard-copy">
    <form method="post" id="copyForm">
        <h1>复制-添加新订单</h1>
        <div class="wizard-card" data-onValidated="setServerName" data-cardname="name">
            <h3><span>基本信息</span></h3>
            <input type="hidden" name="oid_copy">
            <div class="wizard-input-section">
                <div class="form-group">
                    <label>客户名称</label>
                    <select class="form-control" name="client_copy" id="client_copy" data-validate="">
                        {volist name="clients" id="v"}
                        <option value="{$v.cid}">{$v.state} {$v.client}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group">
                    <label>客户联系方式</label>
                    <input type="text" class="form-control" name="client_contacts_copy" id="client_contacts_copy" data-validate=""/>
                </div>
                <div class="form-group">
                    <label>下单联系人</label>
                    <input type="text" class="form-control" name="order_placer_copy" id="order_placer_copy" data-validate=""/>
                </div>
                <div class="form-group">
                    <label>下单联系人电话</label>
                    <input type="text" class="form-control" name="placer_phone_copy" id="placer_phone_copy" data-validate=""/>
                </div>
                <div class="form-group">
                    <label>国内货运</label>
                    <textarea type="text" class="form-control" name="transport_copy" id="transport_copy" data-validate=""></textarea>
                </div>
            </div>

        </div>

        <div class="wizard-card" data-cardname="group" id="forMeterC">
            <h3><span>表计参数</span></h3>

            <div class="wizard-input-section">
                <div class="form-group">
                    <label class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="text-align: center;">基表型号</label>
                    <lable class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="text-align: center;">表数量</lable>
                </div>
            </div>
            <!--<div class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
                <div class="form-group">
                    <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                        <select class="form-control" name="meter_id_copy[0]" id="meter_id" data-validate="">
                            <option value="0">N/A</option>
                            {volist name="meterTypes" id="v"}
                            <option value="{$v['meter_id']}">{$v.meter_type} {$v.caliber}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                        <input type="text" class="form-control" name="order_qty_copy[0]" id="order_qty" data-validate=""/>
                    </div>
                </div>
            </div>-->
            <div class="wizard-input-section" id="newMeterC"></div>
            <div class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
                <button type="button" id="copyAddMeter" style="margin-left: 8px;">添加基表型号</button>
            </div>
            <div class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
                <div class="form-group">
                    <label>方案</label>
                    <select class="form-control" name="pro_id_copy" id="pro_id_copy" data-validate="" onchange="getProCopy(this.options[this.options.selectedIndex].value)">
                        {volist name="programs" id="v"}
                        <option value="{$v['pro_id']}">{$v.pro_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
        </div>

        <div class="wizard-card" data-cardname="services" id="copyForFit">
            <h3><span>配件信息</span></h3>
            <div class="wizard-input-section">
                <div class="form-group">
                    <label class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="text-align: center;">配件名称</label>
                    <label class="col-md-6 col-sm-6 col-lg-6 col-xs-6" style="text-align: center;">配件数量</label>
                </div>
            </div>
            <!--树-->
            <!--<div class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
                <div class="form-group">
                    <div class="col-md-6 col-sm-6 col-lg-6">
                        <select type="checkbox" id="fid_copy" name="fid_copy[0]"
                                class="col-md-12 col-sm-12 col-lg-12">
                            {volist name="fittings" id="v"}
                            <option value="{$v['fid']}">{$v.fitting}</option>
                            {/volist}
                        </select>
                    </div>
                    &lt;!&ndash;<div class="col-md-2 col-sm-2 col-lg-2"></div>&ndash;&gt;
                    <div class="col-md-6 col-sm-6 col-lg-6">
                        <input type="text" name="fid_num_copy[0]" class="col-md-12 col-sm-12 col-lg-12">
                    </div>
                </div>
            </div>-->
            <div class="wizard-input-section" id="copyFor"></div>
            <div class="wizard-input-section">
                <button type="button" id="copyFit" style="margin-left: 16px;">添加配件</button>
            </div>
        </div>

        <div class="wizard-card" data-onload="" data-cardname="location">
            <h3><span>基表参数</span></h3>

            <div class="wizard-input-section" id="meterParamsC">
                <div class="form-group">
                    <label>内置止回阀</label>
                    <select class="form-control" name="is_valve_copy" id="is_valve_copy" data-validate="">
                        <option value="1">带</option>
                        <option value="0">不带</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>内置滤网</label>
                    <select class="form-control" name="is_sieve_copy" id="is_sieve_copy" data-validate="">
                        <option value="1">带</option>
                        <option value="0">不带</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>铭牌信息</label>
                    <select class="form-control" name="nameplate_copy" id="nameplate_copy" data-validate="">
                        <option value="标准型Laison">标准型Laison</option>
                        <option value="客户化">客户化</option>
                        <option value="空">空</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>是否带唛头</label>
                    <select class="form-control" name="is_mark_copy" id="is_mark_copy" data-validate="">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="wizard-card">
            <h3><span>技术参数</span></h3>

            <div class="wizard-input-section">
                <div class="form-group" id="chain_copy_d">
                    <label>固定/动态信道</label>
                    <select class="form-control" name="chain_copy" id="chain_copy" data-validate="">
                        <option value="固定信道">固定信道</option>
                        <option value="动态信道">动态信道</option>
                    </select>
                </div>
                <div class="form-group" id="is_infrade_copy_d">
                    <label>红外开关</label>
                    <select class="form-control" name="is_infrade_copy" id="is_infrade_copy" data-validate="">
                        <option value="1">开启</option>
                        <option value="0">关闭</option>
                    </select>
                </div>
                <div class="form-group forhid" id="start_edit">
                    <label>表号长度</label>
                    <select name="meter_len_copy" id="meter_len_copy" class="form-control">
                        <option value="0"></option>
                        <option value="11">11位表号</option>
                        <option value="13">13位表号</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>出厂阀门状态</label>
                    <select class="form-control" name="valve_status_copy" data-validate="">
                        <option value="关">关</option>
                        <option value="开">开</option>
                    </select>
                </div>

                <div class="form-group">
                    <label>计量模式</label>
                    <select class="form-control" name="measure_mode_copy" id="measure_mode_copy" data-validate="">
                        <option value="1">按金额计算</option>
                        <option value="0">按体积计算</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>报警量</label>
                    <input type="text" class="form-control" name="alarm_copy" id="alarm_copy" data-validate=""/>
                </div>
                <div class="form-group">
                    <label>透支量</label>
                    <input type="text" class="form-control" name="overdraft_copy" id="overdraft_copy" data-validate=""/>
                </div>
                <div class="form-group">
                    <label>时区</label>
                    <input type="text" class="form-control" name="timezone_copy" id="timezone_copy" data-validate=""/>
                </div>
            </div>
        </div>


        <div class="wizard-card">
            <h3><span>软件信息</span></h3>

            <div class="wizard-input-section">
                <div class="form-group">
                    <label>软件来源</label>
                    <select class="form-control" name="soft_from_copy" data-validate="" onchange="setSectioncopy(this.options[this.options.selectedIndex].value)">
                        <option value="LAISON系统">LAISON系统</option>
                        <option value="第三方软件">第三方软件</option>
                    </select>
                </div>
            </div>
            <div class="wizard-input-section" id="soft_section_copy">
                <div class="form-group">
                    <label>加密方式</label>
                    <select class="form-control" name="crypt_copy" id="crypt_copy" data-validate="" onchange="getCryptCopy(this.options[this.options.selectedIndex].value)">
                        <option value="软加密">软加密</option>
                        <option value="硬加密">硬加密</option>
                    </select>
                </div>
                <div class="form-group forhid" id="sgc_copy_d">
                    <label>SGC号</label>
                    <input type="text" class="form-control" name="sgc_copy" id="sgc_copy">
                </div>
                <div class="form-group forhid" id="cry_utk_copy_d">
                    <label>表计出厂密钥状态</label>
                    <select class="form-control" name="cry_utk_copy" id="cry_utk_copy" data-validate="">
                        <option value="DDTK">DDTK</option>
                        <option value="DUTK">DUTK</option>
                    </select>
                </div>

                <!--<div class="form-group">
                    <label>软件版本</label>
                    <select class="form-control" name="soft_version_copy" id="soft_version_copy" data-validate="">
                        <option value="B/S">B/S</option>
                        <option value="C/S">C/S</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>数据库</label>
                    <select class="form-control" name="sql_db_copy" id="sql_db_copy" data-validate="">
                        <option value="Access">Access</option>
                        <option value="SQL">SQL</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>是否需要usbkey</label>
                    <select class="form-control" name="is_usbkey_copy" id="is_usbkey_copy" data-validate="">
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>-->
            </div>
        </div>

        <div class="wizard-card">
            <h3><span>其他信息</span></h3>
            <div class="wizard-input-section">
                <div class="form-group">
                    <label>所属业务部门</label>
                    <select class="form-control" name="sale_id_copy" id="sale_id_copy" data-validate="saleNotNullCopy">
                        <option value="1">业务一部</option>
                        <option value="2">业务二部</option>
                        <option value="3">业务三部</option>
                        <option value="4">业务四部</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>订单金额-单位</label>
                    <div>
                        <input type="text" name="amounts_copy" id="amounts_copy" class="new-sum">
                        <select name="unit_copy" id="unit_copy" class="new-units">
                            <option value="$">$</option>
                            <option value="￥">￥</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label>备注</label>
                    <input type="text" name="other_copy" class="form-control" data-validate="">
                </div>
            </div>
        </div>

    </form>
</div>
<!--修改弹出框-->
<script src="__JS__/jquery.js"></script>
<script type="text/javascript">

    /*设置原有的配件信息*/
    /*var jsonfitting = '{$jsonfittings}';
    jsonfitting = JSON.parse(jsonfitting)
    //console.log(jsonfitting)
    var fidArr = []
    for(var i=0;i<jsonfitting.length;i++){
        fidArr[i] = jsonfitting[i].fid
    }*/
    function setFitCopy(fid) {
        $(`<div id="cForm" class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
            <div class="form-group">
                <div class="col-md-5 col-sm-6 col-lg-6 col-xs-6">
                    <select type="checkbox" id="fid_copy[${fid}]" name="fid_copy[${fid}]" autocomplete="off"
                            class="col-md-12 col-sm-12 col-lg-12">
                        <option value=""></option>
                        {volist name="fittings" id="v"}
                        <option value="{$v['fid']}">{$v.fitting}</option>
                        {/volist}
                    </select>
                </div>
                <!--<div class="col-md-2 col-sm-2 col-lg-2"></div>-->
                <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                    <input type="text" name="fid_num_copy[${fid}]" class="col-md-12 col-sm-12 col-lg-12" autocomplete="off">
                </div>
                <button type="button" class="delE" style="margin-left: 8.1px;margin-top: 1px;">删除配件</button>
            </div>
          </div>
        `).appendTo('#copyFor');

    }
    /*设置原有的配件信息*/

    /*修改前清空配件记录*/
    function setFitNullCopy() {
        $('#copyFor').html('')
    }

    function copy(oid) {
        //post前设为同步
        //$.ajaxSettings.async = false;
        $.post("{:url('Order/onepa')}",{oid:oid},function(data){
            // console.log(data);
            //主表订单
            if(data) {
                $("input[name='oid_copy']").val(data[0].oid);
                /*基本信息*/
                $("select[name='client_copy']").val(data[0].cid);
                $("input[name='client_contacts_copy']").val(data[0].client_contacts);
                $("input[name='order_placer_copy']").val(data[0].order_placer);
                $("input[name='placer_phone_copy']").val(data[0].placer_phone);
                $("textarea[name='transport_copy']").val(data[0].transport);
                /*表计参数*/
                var meters = new Array()
                meters = data[0].meters;
                // console.log(meters.length)
                setMeterNullCopy();
                if(meters.length != 0){
                    $('#meterParamsC').removeClass('forhid')
                    var m_id = new Array()
                    var m_num = new Array()
                    // console.log(meters)
                    for(var j=0;j<meters.length;j++){
                        m_id[j] = meters[j].mId;
                        m_num[j] = meters[j].mNum;
                        setMeterCopy(j);
                        $("select[name='meter_id_copy["+j+"]']").val(m_id[j]);
                        $("input[name='order_qty_copy["+j+"]']").val(m_num[j]);
                    }
                }else{
                    $('#meterParamsC').addClass('forhid')
                }
                setCopyMeter(meters.length-1)

                $("select[name='pro_id_copy']").val(data[0].pro_id);
                //根据方案内容显示
                getProCopy(data[0].pro_id);

                /*配件信息*/
                var fids = []
                fids = data[0].fids;
                //先清空原来的数据
                setFitNullCopy();
                if(fids.length != 0){
                    var fid = new Array()
                    var fidNum = new Array()
                    for(var i=0;i<fids.length;i++){
                        fid[i] = fids[i].fid;
                        fidNum[i] = fids[i].fid_num;
                        //console.log(fid[i])
                        setFitCopy(i)
                        $("select[name='fid_copy["+i+"]']").val(fid[i])
                        $("input[name='fid_num_copy["+i+"]']").val(fidNum[i]);
                    }
                }
                /*新添加的配件*/
                setCopyFit(fids.length-1)

                /*基表参数*/
                $("select[name='is_valve_copy']").val(data[0].is_valve);
                $("select[name='is_sieve_copy']").val(data[0].is_sieve);
                $("select[name='nameplate_copy']").val(data[0].nameplate);
                $("select[name='is_mark_copy']").val(data[0].is_mark);
                /*技术参数*/
                $("select[name='chain_copy']").val(data[0].chain);
                $("select[name='is_infrade_copy']").val(data[0].is_infrade);
                $("select[name='measure_mode_copy']").val(data[0].measure_mode);
                $("input[name='alarm_copy']").val(data[0].alarm);
                $("input[name='overdraft_copy']").val(data[0].overdraft);
                $("input[name='timezone_copy']").val(data[0].timezone);
                $("select[name='valve_status_copy']").val(data[0].valve_status);
                //新添加的:开始表号和结束表号
                $("select[name='meter_len_copy']").val(data[0].meter_len);

                /*软件信息*/
                var soft_from = data[0].soft_from;
                if(soft_from == '第三方软件'){
                    $('#soft_section_copy').addClass('forhid')
                }else{
                    $('#soft_section_copy').removeClass('forhid')
                }
                $("select[name='soft_from_copy']").val(soft_from)
                $("select[name='crypt_copy']").val(data[0].crypt);
                getCryptCopy(data[0].crypt)
                //新添加的：sgc 出厂密钥
                $("input[name='sgc_copy']").val(data[0].sgc);
                $("select[name='cry_utk_copy']").val(data[0].cry_utk);

                /*$("select[name='soft_version_copy']").val(data[0].soft_version);
                $("select[name='sql_db_copy']").val(data[0].sql_db);
                $("select[name='is_usbkey_copy']").val(data[0].is_usbkey);*/
                /*其他*/
                $("select[name='sale_id_copy']").val(data[0].sale_id)
                $("input[name='other_copy']").val(data[0].other);
                $("input[name='amounts_copy']").val(data[0].sum_amounts)
                $("select[name='unit_copy']").val(data[0].sum_units)
            }
        },'json');
        forcopy.show()
        forcopy.on("submit", function(wizard) {
            setTimeout(function() {
                wizard.trigger("success");
                wizard.hideButtons();
                wizard._submitting = false;
                wizard.showSubmitCard("success");
                wizard.updateProgressBar(0);
            }, 3000);
            esavecopy();
            forcopy.reset().close();
            //刷新页面
            window.location.reload();
        });

    }
    function esavecopy() {
        var oid = $("input[name='oid_copy']").val();
        /*基本信息*/
        var client = $("select[name='client_copy']").val();
        var client_contacts = $("input[name='client_contacts_copy']").val();
        var order_placer = $("input[name='order_placer_copy']").val();
        var placer_phone = $("input[name='placer_phone_copy']").val();
        var transport = $("textarea[name='transport_copy']").val();
        /*表计参数*/
        var meter_id = '';
        var order_qty = '';
        var meter_id_arr = []
        var order_qty_arr = []
        // console.log('meterV' + meterV)
        for(var i=0;i<10;i++){
            meter_id_arr[i] = $("select[name='meter_id_copy["+i+"]']").val();
            order_qty_arr[i] = $("input[name='order_qty_copy["+i+"]']").val();
            if(meter_id_arr[i] == undefined){
                continue;
            }
            meter_id = meter_id + meter_id_arr[i] + ',';
            order_qty = order_qty + order_qty_arr[i] + ',';
        }
        var pro_id = $("select[name='pro_id_copy']").val();
        /*配件信息*/
        var fid1 = []
        var fid_num1 = []

        var fid = '';
        var fid_num = '';

        for (var k=0;k<11;k++){
            var temp = $("select[name='fid_copy["+k+"]']").val()
            if(temp == undefined){
                continue;
            }
            fid1[k] = $("select[name='fid_copy["+k+"]']").val();
            fid_num1[k] = $("input[name='fid_num_copy["+k+"]']").val();

            fid = fid + fid1[k] + ','
            fid_num = fid_num + fid_num1[k] + ','
        }
        /*基表参数*/
        var is_valve = '';
        var is_sieve = '';
        var nameplate = '空';
        var is_mark = '';
        if(meter_id != ''){
            is_valve = $("select[name='is_valve_copy']").val();
            is_sieve = $("select[name='is_sieve_copy']").val();
            nameplate = $("select[name='nameplate_copy']").val();
            is_mark = $("select[name='is_mark_copy']").val();
        }
        /*技术参数*/
        var chain = $("select[name='chain_copy']").val();
        var is_infrade = $("select[name='is_infrade_copy']").val();
        var measure_mode = $("select[name='measure_mode_copy']").val();
        var alarm = $("input[name='alarm_copy']").val();
        var overdraft = $("input[name='overdraft_copy']").val();
        var timezone = $("input[name='timezone_copy']").val();
        var valve_status = $("select[name='valve_status_copy']").val();
        //新添加的:表号长度
        var meter_len = $("select[name='meter_len_copy']").val();

        /*软件信息*/
        var soft_from = $("select[name='soft_from_copy']").val();

        var crypt = $("select[name='crypt_copy']").val();
        //新添加的：sgc 出厂密钥
        var sgc = $("input[name='sgc_copy']").val();
        var cry_utk = $("select[name='cry_utk_copy']").val();
        //第三方软件
        if(soft_from == '第三方软件'){
            crypt = null;
            //新添加的：sgc 出厂密钥
            sgc = null;
            cry_utk = null;
        }

        /* var soft_version = $("select[name='soft_version_copy']").val();
         var sql_db = $("select[name='sql_db_copy']").val();
         var is_usbkey = $("select[name='is_usbkey_copy']").val();*/
        /*其他信息*/
        var saleId = $("select[name='sale_id_copy']").val()
        var other = $("input[name='other_copy']").val();
        var amounts = $("input[name='amounts_copy']").val()
        var unit = $("select[name='unit_copy']").val()

        var data = {'cid':client,'client_contacts':client_contacts,'order_placer':order_placer,'placer_phone':placer_phone,'transport':transport,
            'meter_id':meter_id,'order_qty':order_qty,'pro_id':pro_id,'fid':fid,'fid_num':fid_num,
            'is_valve':is_valve,'is_sieve':is_sieve,'nameplate':nameplate,'is_mark':is_mark,
            'meter_len':meter_len,'sgc':sgc,'cry_utk':cry_utk,
            'chain':chain,'is_infrade':is_infrade,'measure_mode':measure_mode,'alarm':alarm,'overdraft':overdraft,'timezone':timezone,'valve_status':valve_status,
            'soft_from':soft_from,
            'crypt':crypt,'other':other,'sale_id':saleId,'sum_amounts':amounts,'sum_units':unit};
        // console.log(data)
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "{:url('Order/save')}",//url
            data: data,
            success: function (result) {
                //console.log(result)
                var code = result.code
                var msg = result.msg
                var need = result.need
                //console.log(need)
                changeText(msg, code)
                //console.log('123'+code)
            },
            error:function (result) {
                var code = 0
                var msg = '服务器错误';
                changeText(msg, code)

            }
        });
    }
    /*加密方式如果选择的是硬加密，显示SGC号和表计出场密钥状态（DDTK，DUTK）；*/
    function getCryptCopy(crypt) {
        if(crypt == '硬加密'){
            $('#cry_utk_copy_d').removeClass('forhid')
            $('#sgc_copy_d').removeClass('forhid')
        }else{
            $('#cry_utk_copy_d').addClass('forhid')
            $('#sgc_copy_d').addClass('forhid')
        }
    }
    //方案选择
    function getProCopy(pro_id) {
        //console.log(123)
        //post前设为同步
        $.ajaxSettings.async = false;
        $.post("{:url('Program/one')}",{pro_id:pro_id},function(data){
            //console.log(data)
            var connect_way = ''
            var pro_pay =''
            if(data) {
                //根据方案通讯方式判断后面的显示列
                connect_way = data[0].connect_way;
                pro_pay = data[0].pro_pay
                //console.log(connect_way+','+pro_pay+'123')
                //0RFID_V5,1STS_RFID,2STS_IR,3STS_LORA,4STS_NBIot,5STS_GPRS
                if(connect_way == 1){
                    $('#chain_copy_d').addClass('forhid')
                }else if(connect_way == 0){
                    $('#chain_copy_d').addClass('forhid')
                    $('#is_infrade_copy_d').addClass('forhid')
                }else{
                    $('#chain_copy_d').removeClass('forhid')
                    $('#is_infrade_copy_d').removeClass('forhid')
                }
                if(pro_pay == 0){
                    //如果方案是STS(红外和lora)预付费或者STS射频卡预付费，那么技术参数那一栏目，需要增加表号（11位还是13位）；
                    if((connect_way == 1) || (connect_way == 2) || (connect_way == 3)){
                        $('#start_edit').removeClass('forhid')
                    }else{
                        $('#start_edit').addClass('forhid')
                    }
                }else{
                    $('#start_edit').addClass('forhid')
                }

            }
        },'json');
    }
    /*
    * 添加配件
    * */
    function setCopyFit(vaid_edit) {
        /*配件*/
        $('#copyFit').click(function () {
            vaid_edit++;
            $(`<div id="cForm" class="wizard-input-section col-sm-12 col-md-12 col-xs-12">
            <div class="form-group">
                <div class="col-md-5 col-sm-6 col-lg-6">
                    <select type="checkbox" id="fid_copy[${vaid_edit}]" name="fid_copy[${vaid_edit}]"
                            class="col-md-12 col-sm-12 col-lg-12">
                        {volist name="fittings" id="v"}
                        <option value="{$v['fid']}">{$v.fitting}</option>
                        {/volist}
                    </select>
                </div>

                <div class="col-md-6 col-sm-6 col-lg-6">
                    <input type="text" name="fid_num_copy[${vaid_edit}]" class="col-md-12 col-sm-12 col-lg-12">
                </div>
                <button type="button" class="delE" style="margin-left: 8.1px;margin-top: 1px;">删除配件</button>
            </div>
          </div>
        `).appendTo('#copyFor');
        })
        $(function(){
            $('#copyForFit').delegate(".delE","click",function(){
                //alert(123);
                $(this).closest('#cForm').remove();
                vaid_edit--;
            });
        });
    }
    //软件来源，如果是第三方软件，则不需要填写以下信息
    function setSectioncopy(val) {
        if(val == '第三方软件'){
            $('#soft_section_copy').addClass('forhid')
        }else{
            $('#soft_section_copy').removeClass('forhid')
        }

    }

    /*新添加的基表型号+数量*/
    function setCopyMeter(editV) {
        $('#copyAddMeter').click(function () {
            editV++;
            $(`
            <div class="wizard-input-section col-sm-12 col-md-12 col-xs-12" id="fromMeterE">
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                            <select class="form-control" name="meter_id_copy[${editV}]" data-validate="">
                                <option value="0">N/A</option>
                                {volist name="meterTypes" id="v"}
                                <option value="{$v['meter_id']}">{$v.meter_type} {$v.caliber}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                            <input type="text" class="form-control" name="order_qty_copy[${editV}]" data-validate=""/>
                        </div>
                    </div>
                    <button type="button" class="delMeterE" style="margin-left: 8.1px;margin-top: 1px;">删除基表型号</button>
                </div>
            `).appendTo('#newMeterC')
            // var meterId = $("select[name='meter_id_copy[0]']").val()
            isMeterNullCopy(editV);
        })
        $(function () {
            $('#forMeterC').delegate(".delMeterE",'click',function () {
                $(this).closest('#fromMeterE').remove();
                editV--;
                // console.log(editV) //-1
                isMeterNullCopy(editV);
            })
        })


    }
    /*修改前清空基表型号记录*/
    function setMeterNullCopy() {
        $('#newMeterC').html('')
    }
    /*现有的基表型号+数量*/
    function setMeterCopy(m_id) {
        $(`
        <div class="wizard-input-section col-sm-12 col-md-12 col-xs-12" id="fromMeterE">
                <div class="form-group">
                    <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                        <select class="form-control" name="meter_id_copy[${m_id}]" data-validate="">
                            <option value="0">N/A</option>
                            {volist name="meterTypes" id="v"}
                            <option value="{$v['meter_id']}">{$v.meter_type} {$v.caliber}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="col-md-6 col-sm-6 col-lg-6 col-xs-6">
                        <input type="text" class="form-control" name="order_qty_copy[${m_id}]" data-validate=""/>
                    </div>
                </div>
                <button type="button" class="delMeterE" style="margin-left: 8.1px;margin-top: 1px;">删除基表型号</button>
            </div>
     `).appendTo('#newMeterC')

    }
    /*是否需要显示基表参数*/
    function isMeterNullCopy(editV) {
        if(editV == -1){
            // $('#isMeterNullCopy').val(0)
            $('#meterParamsC').addClass('forhid')
        }else{
            $('#meterParamsC').removeClass('forhid')
        }
    }
    function saleNotNullCopy(el) {
        var val = el.val()
        ret = {
            status: true
        };
        if (val == '') {
            ret.status = false;
            ret.msg = "请选择业务部门";
        }
        return ret;
    }

</script>
